<!DOCTYPE html>
<html lang="zh-cn" ng-app="app">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, maximum-scale=1">
    <title id="title">{$title|default="页面标题"}</title>

    <link rel="shortcut icon" href="/static/img/favicon.ico"/>

    <link rel="stylesheet" href="/static/plugs/awesome/css/font-awesome.min.css?ver={:date('ymd')}">


    <!--bootstrap-->
    <link href="/static/js/bootstrap-4.1.3/css/bootstrap.css" rel="stylesheet">
    <!-- bootstrap-table -->
    <link rel="stylesheet" href="/static/js/bootstrap-table-1.12.1/bootstrap-table.min.css">
    <!-- bootstrap-table-treegrid -->
    <link rel="stylesheet" href="/static/js/jquery-treegrid/css/jquery.treegrid.css">
    <!-- bootstrap-select -->
    <link rel="stylesheet" href="/static/css/bootstrap-select.min.css">
    <!-- bootstrap-table-jump 分页跳转 -->
    <link href="/static/css/bootstrap-table-pagejump.css" rel="stylesheet">
    <!--layer-->
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <!-- 时间控件 -->
    <link rel="stylesheet" href="/static/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
    <!-- 公共的css -->
    <link rel="stylesheet" href="/static/css/style.css?v={:date('ymdhis')}" media="all"/>

    <link rel="stylesheet" href="/static/js/ptimg/ptimg.css">

    <style> [ng-cloak]{display:none !important} </style>
    <style>
        .table{
            table-layout: fixed;
        }
        .table > thead > tr > th {
            font-weight: bold;
        }
        /*td{*/

        /*    word-break: keep-all !important; !* 不换行 *!*/
        /*    white-space: nowrap !important; !* 不换行 *!*/
        /*    overflow: hidden !important; !* 内容超出宽度时隐藏超出部分的内容 *!*/
        /*    text-overflow: ellipsis !important; !* for IE *!*/
        /*}*/
        /*隐藏页面右侧下拉条*/
        /*body {*/
        /*    overflow-x: hidden;*/
        /*    overflow-y: hidden;*/
        /*}*/

        .bootstrap-table table thead th{
            text-align: center;
        }
    </style>
    <script src="/static/js/echarts.min.js"></script>

    {block name="css"}{/block}
</head>
<body ng-cloak >

{block name="main"}{/block}

<!--jquery-->
<script src="/static/js/jquery-3.3.1.min.js"></script>

<!--popper-->
<script src="/static/js/popper-1.14.4.min.js"></script>

<!--bootstrap-->
<script src="/static/js/bootstrap-4.1.3/js/bootstrap.js"></script>
<!-- bootstrap-table -->
<script src="/static/js/bootstrap-table-1.12.1/bootstrap-table.min.js"></script>
<script src="/static/js/bootstrap-table-1.12.1/bootstrap-table-zh-CN.js"></script>
<!-- bootstrap-table-treegrid -->
<script src="/static/js/jquery-treegrid/js/jquery.treegrid.js"></script>
<script src="/static/js/bootstrap-table-1.12.1/extensions/treegrid/bootstrap-table-treegrid.js"></script>
<!-- bootstrap-select -->
<script src="/static/js/bootstrap-select.min.js"></script>

<!-- bootstrap-table-jump 分页跳转 -->
<script src="/static/js/bootstrap-table-pagejump.js"></script>

<!--layer-->
<script src="/static/js/layer-3.1.1/layer.js"></script>

<!-- 时间控件 -->
<script src="/static/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script src="/static/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>

<!--表单图片上传-->
<script src="/static/js/ptimg/ptimg.js?v={:config('FileVersion')}&a={:date('ymdhis')}"></script>
<!-- 公共的js -->
<script src="/static/js/function.js?ver={:date('ymdhis')}"></script>
<script src="/static/js/frame.js?ver={:date('ymdhis')}"></script>
<script src="/static/js/bst.js?ver={:date('ymdhis')}"></script>
<script src="/static/js/bsEdit.js?ver={:date('ymdhis')}"></script>
<script src="/static/js/fs.js?ver={:date('ymdhis')}"></script>
<!--<script src="/static/js/area.js?ver={:date('ymdhis')}"></script>-->

<!-- 时间控件 -->
<script src="/static/js/My97DatePicker/WdatePicker.js"></script>

<script>window.ROOT_URL = '__PUBLIC__';</script>

<!--Angular-->
<script src="/static/qc/angular.min.js"></script>


<!--layui-->
<script src="/static/layui/layui.js"></script>

<!--自定义 QC  JS-->
<script src="/static/qc/qc.js?v={:config('FileVersion')}&a={:date('ymdhis')}"></script>
<script src="/static/qc/format_txt.js?v={:config('FileVersion')}&a={:date('ymdhis')}"></script>
<script src="/static/qc/app.js?v={:config('FileVersion')}&a={:date('ymdhis')}"></script>
<script>
    //当前用户
    let current_user = {$Think.session.MAP_USER};
    let parentIframe = parent.$('body').find('.iframes iframe:visible')[0].contentWindow;
    let current_date = "{:get_current_date()}";
</script>
<!--当前页面JS-->
{block name="script"}
{/block}
<script>

    function in_array_object(value,arr)
    {
        for(let k in arr)
        {
            if(JSON.stringify(value) == JSON.stringify(arr[k]))
            {
                return k;
            }
        }
        return -1;
    }

    //初始话参数
    let config = {
        Title: $('.ibox-title').find('H5').text(),
        TableId: PageConfig.TableId ? '#' + PageConfig.TableId : '',
        GetListUrl: PageConfig.GetListUrl ? PageConfig.GetListUrl : '',
        SortName: PageConfig.SortName ? PageConfig.SortName : 'id',
        SortOrder: PageConfig.SortOrder ? PageConfig.SortOrder : 'DESC',
        Area: PageConfig.Area ? PageConfig.Area : ['800px', '500px'],
        InfoUrl: PageConfig.InfoUrl ? PageConfig.InfoUrl : '',
        DeleteUrl: PageConfig.DeleteUrl ? PageConfig.DeleteUrl : '',
        AuditUrl: PageConfig.AuditUrl ? PageConfig.AuditUrl : '',
        ImportUrl: PageConfig.ImportUrl ? PageConfig.ImportUrl : '',
        ImportDetailUrl: PageConfig.ImportDetailUrl ? PageConfig.ImportDetailUrl : '',
        ImportFileUrl: PageConfig.ImportFileUrl ? PageConfig.ImportFileUrl : '',
        TemplateUrl: PageConfig.TemplateUrl ? PageConfig.TemplateUrl : '',
        TableColumns: PageConfig.TableColumns ? PageConfig.TableColumns : [],
    };

    //刷新当前页面
    function bind() {
        $(config.TableId).bootstrapTable("refresh");
    }

    //搜索按钮
    $('body').on('click', '#search', function () {
        var pt_tab = $(".more_search_all").css('display');
        if (pt_tab == 'none') {
            $('.more_search_all').attr('style', 'display:block');
        }
        var index = layer.load(1, {
            shade: [0.1,'#fff'], //0.1透明度的白色背景,
        });
        bind();
    });

    //新增按钮
    function add() {
        parent.layer.open({
            title: config.Title + '新增', type: 2, area: config.Area, fix: true, maxmin: false
            , content: config.InfoUrl + '?id=0', end: function () {
                //bind();
            }
        });
    }

    //编辑按钮
    function edit() {
        let rows = $(config.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "您没有选中任何项,请您选中后再操作。"});
            return false;
        }
        if (rows.length > 1) {
            oob.showIframe({code: -1, msg: "很抱歉,一次只能选择一条记录。"});
            return false;
        }
        parent.layer.open({
            title: config.Title + '编辑', type: 2, area: config.Area, fix: true, maxmin: false
            , content: config.InfoUrl + '?id=' + rows[0]['id'], end: function () {
                //bind();
            }
        });
    }

    //删除按钮
    function del() {
        let rows = $(config.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "请勾选要删除的行"});
            return false;
        }
        let data = [];
        let rowsLength = rows.length;
        for (let i = 0; i < rowsLength; i++) {
            data.push(rows[i]["id"]);
        }
        parent.layer.confirm('确认要删除这' + data.length + '条选中的行吗？', {
            btn: ['确定', '取消']
        }, function () {
            oob.ajaxIframe({
                url: config.DeleteUrl,
                type: "post",
                data: {"ids": data}
            }).then(function (data) {
                oob.showIframe(data);
                if (data.code == 0) {
                    bind();
                }
            });
        });
    }

    //审核按钮
    function audit() {
        let rows = $(config.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "请勾选要审核的行"});
            return false;
        }
        let html = '<div class="form-check form-check-inline">\n' +
            '        <input class="form-check-input" type="radio" id="audit_state_yes" value="1" name="audit_state">\n' +
            '        <label class="form-check-label" for="audit_state_yes">审核通过</label>\n' +
            '    </div>\n' +
            '    <div class="form-check form-check-inline">\n' +
            '        <input class="form-check-input" type="radio" id="audit_state_no" value="2" name="audit_state">\n' +
            '        <label class="form-check-label" for="audit_state_no">审核不通过</label>\n' +
            '    </div>';
        parent.layer.confirm(html, function (index) {
            let value = $('[name="audit_state"]:checked').val();
            if (typeof (value) == 'undefined') {
                oob.showIframe({code: -1, msg: "请选择审核状态"});
                parent.layer.close(index);
                return false;
            }
            let stateMsg = value == 1 ? '审核通过' : '审核不通过';
            parent.layer.confirm('确定要将选中的行置为' + stateMsg + '状态吗？', {icon: 3, title: '提示'}, function (index_is) {

                let data = [];
                let rowsLength = rows.length;
                for (let i = 0; i < rowsLength; i++) {
                    data.push(rows[i]["id"]);
                }
                oob.ajaxIframe({
                    url: config.AuditUrl,
                    type: "post",
                    data: {"ids": data, 'audit_state': value}
                }).then(function (data) {
                    oob.showIframe(data);
                    if (data.code == 0) {
                        bind();
                    }
                });
                parent.layer.close(index_is);
            });
            parent.layer.close(index);
        });
    }

    //模板下载
    function template() {
        let a = $("<a href='" + config.TemplateUrl + "' target='_blank'>baidu</a>").get(0);
        let e = document.createEvent('MouseEvents');
        e.initEvent('click', true, true);
        a.dispatchEvent(e);
    }

    let TableInit = function ($scope) {
        let oTableInit = new Object();
        oTableInit.Init = function () {
            $(config.TableId).bootstrapTable({
                url: config.GetListUrl,
                method: 'get',
                //是否显示行间隔色
                striped: true,
                theadClasses: 'thead-light',
                rememberOrder: true,
                cache: false,
                sidePagination: 'server',
                queryParams: function (params) {
                    $.extend(true, params, $scope.model);

                    return params;
                },
                pagination: true,
                pageNumber: 1,
                pageSize: 25,
                pageList: [25, 50, 75, 100, 'All'],
                //是否启用点击选中行
                clickToSelect: true,
                uniqueId: "id",
                sortName: config.SortName,
                sortOrder: config.SortOrder,
                columns: config.TableColumns,
                onLoadSuccess: function () {
                    //设置表格高度
                    $(config.TableId).bootstrapTable('resetView', {height: $(".iframes", parent.document).height() - $(".ibox-title").height() - $(".search-form").height() - 25});
                    layer.closeAll();
                }
            });

        };
        return oTableInit;
    };

    //关闭当前弹窗
    $('body').on('click', '.btn-cancel', function () {
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    });
    
    //导出
    function s_export() {
        frame.daochu($(config.TableId));
    }


    //Excel导入 特殊处理
    $("[data-button]").bind('DOMNodeInserted', function(e) {
        if($(e.target).find('.a-import').length > 0){
            layui.use('upload', function(){
                layui.upload.render({
                    elem: $('body').find('.a-import')
                    ,url: config.ImportUrl
                    ,accept: 'file'
                    ,exts: 'xls|xlsx'
                    ,before: function(){
                        layer.load(2 ,{ icon: 2 ,shade: 0.1 });
                    }
                    ,done: function(data){
                        layer.closeAll();
                        oob.show(data);
                        if(data.code == 0){
                            bind();
                        }
                    }
                    ,error: function(data){
                        layer.closeAll();
                        oob.show({code:-1,msg:"请求过程中发生异常；"+data});
                    }
                });
            });
            //移除监听事件
            $("[data-button]").unbind("DOMNodeInserted")
        }
    });

</script>
</body>
</html>